package cn.krund.lyc.hotlerobot.utils;

import android.content.Context;
import android.content.SharedPreferences;

import cn.krund.lyc.hotlerobot.activity.base.App;

/**
 * @包名: cn.krund.lyc.hotlerobot.utils
 * @作者: 刘育成
 * @时间: 2018/4/5  15:05
 * @org: 克路德人工智能
 * @描述: TODO
 * @fileName: SharedPrefsUtil
 */

public class SharedPrefsUtil {
    public static final String SETTING = "Setting";
    public static final String USERID= "Userid";   //是否到达过二维码存储
    public static final String FIELD= "Field";
    public static final String FIELDAPPKEY= "FieldAppkey";
    public static final String FIELDAPPSECRET= "FieldAppsecret";
    public static final String FIELDID= "FieldId";
    public static final String ACCESSFIELD= "AccessField";    //是否到达过领域存储
    private static final String ROBOTCONTROLSTATE = "ROBOTCONTROLSTATE";
    public static final String VOICE_NAME = "voice_name";     //发言人
    public static final String WELCOME_LOCATION_X = "welcome_x";//设置迎宾地点x坐标
    public static final String WELCOME_LOCATION_Y= "welcome_y";//设置迎宾地点y坐标
    public static final String WELCOME_LOCATION_ANGLE = "welcome_angle";//设置迎宾地点angle
    public static final String WELCOME_LOCATION_NAME = "welcome_name";//设置迎宾地点angle
    public static final String ROBOTNAME = "robotname";//设置迎宾地点angle
    public static final String FREE_CHAT = "freechat";//设置是否开启自由聊天


    /**
     * 保存数据
     * @param context      上下文
     * @param key          键
     * @param value        int类型的值
     */
    public static void putValue(Context context, String key, int value){
        SharedPreferences.Editor sp = context.getSharedPreferences(SETTING,Context.MODE_PRIVATE).edit();
        sp.putInt(key,value);
        sp.commit();
    }

    /**
     * 保存数据
     * @param context      上下文
     * @param key          键
     * @param value        boolean类型的值
     */
    public static void putValue(Context context,String key,boolean value){
        SharedPreferences.Editor sp = context.getSharedPreferences(SETTING,Context.MODE_PRIVATE).edit();
        sp.putBoolean(key,value);
        sp.commit();
    }

    /**
     * 保存数据
     * @param context      上下文
     * @param key          键
     * @param value        String类型的值
     */
    public static void putValue(Context context,String key,String value){
        SharedPreferences.Editor sp = context.getSharedPreferences(SETTING,Context.MODE_PRIVATE).edit();
        sp.putString(key,value);
        sp.commit();
    }

    /**
     *
     * @param context
     * @param key
     * @param value
     */
    public static void putValue(Context context,String key,float value){
        SharedPreferences.Editor sp = context.getSharedPreferences(SETTING,Context.MODE_PRIVATE).edit();
        sp.putFloat(key,value);
        sp.commit();
    }

    /**
     * 获得数据
     * @param context    上下文
     * @param key        键
     * @param defValue   int类型默认值
     * @return    返回int类型的值
     */
    public static int getValue(Context context,String key,int defValue){
        SharedPreferences sp = context.getSharedPreferences(SETTING,Context.MODE_PRIVATE);
        int value = sp.getInt(key,defValue);
        return value;
    }

    /**
     * 获得数据
     * @param context    上下文
     * @param key        键
     * @param defValue   boolean类型默认值
     * @return    返回boolean类型的值
     */
    public static boolean getValue(Context context,String key,boolean defValue){
        SharedPreferences sp = context.getSharedPreferences(SETTING,Context.MODE_PRIVATE);
        boolean value = sp.getBoolean(key,defValue);
        return value;
    }

    /**
     * 获得数据
     * @param context    上下文
     * @param key        键
     * @param defValue   String类型默认值
     * @return    返回String类型的值
     */
    public static String getValue(Context context,String key,String defValue){
        SharedPreferences sp = context.getSharedPreferences(SETTING,Context.MODE_PRIVATE);
        String value = sp.getString(key,defValue);
        return value;
    }

    /**
     * 获得数据
     * @param context    上下文
     * @param key        键
     * @param defValue   float类型默认值
     * @return    返回String类型的值
     */
    public static float getValue(Context context,String key,float defValue){
        SharedPreferences sp = context.getSharedPreferences(SETTING,Context.MODE_PRIVATE);
        float value = sp.getFloat(key,defValue);
        return value;
    }

    /**
     * 到达过二维码页面 存取值得键  userid
     */
    public static void putUserId(Context context,String key,int value){
        SharedPreferences.Editor sp = context.getSharedPreferences(USERID,Context.MODE_PRIVATE).edit();
        sp.putInt(key,value);
        sp.commit();
    }
    /**
     * 到达过二维码页面  存取值得键 userid
     *
     */
    public static int getUserId(Context context,String key,int defValue){
        SharedPreferences sp = context.getSharedPreferences(USERID,Context.MODE_PRIVATE);
        int value = sp.getInt(key,defValue);
        return value;
    }
    /**
     * 机器人领域存储  存取值得键 field
     */
    public static void putUserFieldName(Context context,String key,String value){
        SharedPreferences.Editor sp = context.getSharedPreferences(FIELD,Context.MODE_PRIVATE).edit();
        sp.putString(key,value);
        sp.commit();
    }
    /**
     * 机器人领域获取  存取值得键 field
     */
    public static String getUserFieldName(Context context,String key,String defValue){
        SharedPreferences sp = context.getSharedPreferences(FIELD,Context.MODE_PRIVATE);
        String value = sp.getString(key,defValue);
        return value;
    }

    /**
     * 机器人领域存储  存取值得键 appkey
     */
    public static void putUserFieldAppKey(Context context,String key,String value){
        SharedPreferences.Editor sp = context.getSharedPreferences(FIELDAPPKEY,Context.MODE_PRIVATE).edit();
        sp.putString(key,value);
        sp.commit();
    }
    /**
     * 机器人领域获取  存取值得键 appkey
     */
    public static String getUserFieldAppKey(Context context,String key,String defValue){
        SharedPreferences sp = context.getSharedPreferences(FIELDAPPKEY,Context.MODE_PRIVATE);
        String value = sp.getString(key,defValue);
        return value;
    }

    /**
     * 机器人领域存储  存取值得键 secret
     */
    public static void putUserFieldAppSecret(Context context,String key,String value){
        SharedPreferences.Editor sp = context.getSharedPreferences(FIELDAPPSECRET,Context.MODE_PRIVATE).edit();
        sp.putString(key,value);
        sp.commit();
    }
    /**
     * 机器人领域获取  存取值得键 secret
     */
    public static String getUserFieldAppSecret(Context context,String key,String defValue){
        SharedPreferences sp = context.getSharedPreferences(FIELDAPPSECRET,Context.MODE_PRIVATE);
        String value = sp.getString(key,defValue);
        return value;
    }

    /**
     * 机器人领域id存储  存取值得键 fieldId
     */
    public static void putUserFieldId(Context context,String key,String value){
        SharedPreferences.Editor sp = context.getSharedPreferences(FIELDID,Context.MODE_PRIVATE).edit();
        sp.putString(key,value);
        sp.commit();
    }
    /**
     * 机器人领域id获取  存取值得键 fieldId
     */
    public static String getUserFieldId(Context context,String key,String defValue){
        SharedPreferences sp = context.getSharedPreferences(FIELDID,Context.MODE_PRIVATE);
        String value = sp.getString(key,defValue);
        return value;
    }

    /**
     * 机器人是否到达过领域存储  键access
     */
    public static void putAccessField(Context context,String key,boolean value){
        SharedPreferences.Editor sp = context.getSharedPreferences(ACCESSFIELD,Context.MODE_PRIVATE).edit();
        sp.putBoolean(key,value);
        sp.commit();
    }
    /**
     * 机器人是否到达过领域存储  键access
     */
    public static boolean getAccessField(Context context,String key,boolean defValue){
        SharedPreferences sp = context.getSharedPreferences(ACCESSFIELD,Context.MODE_PRIVATE);
        boolean value = sp.getBoolean(key,defValue);
        return value;
    }
    /**
     * 存放机器人控制的转态   存取值得键  ROBOTCONTROLSTATE
     */
    public static void putRobotControlState(Context context, int robotControlState) {
        SharedPreferences.Editor sp = context.getSharedPreferences(ROBOTCONTROLSTATE, Context.MODE_PRIVATE).edit();
        sp.putInt(ROBOTCONTROLSTATE, robotControlState);
        sp.commit();
    }

    /**
     * 存放机器人控制的转态    存取值得键  ROBOTCONTROLSTATE
     */
    public static int getRobotControlState(Context context) {
        SharedPreferences sp = context.getSharedPreferences(ROBOTCONTROLSTATE, Context.MODE_PRIVATE);
        int value = sp.getInt(ROBOTCONTROLSTATE, -1);
        return value;
    }
    /**
     * 存放机器人名字
     */
    public static void putRobotName(String robotName) {
        SharedPreferences.Editor sp = App.getInstance().getSharedPreferences(ROBOTNAME,Context.MODE_PRIVATE ).edit();
        sp.putString(ROBOTNAME, robotName);
        sp.commit();
    }

    /**
     * 机器人是否播放巡逻标语 键 patrol
     */
    public static void putIsPlayPatrolVoice(Context context,boolean value){
        SharedPreferences.Editor sp = context.getSharedPreferences(ACCESSFIELD,Context.MODE_PRIVATE).edit();
        sp.putBoolean("patrol",value);
        sp.commit();
    }
    /**
     * 机器人是否播放巡逻标语 键 patrol
     */
    public static boolean getIsPlayPatrolVoice(Context context,boolean defValue){
        SharedPreferences sp = context.getSharedPreferences(ACCESSFIELD,Context.MODE_PRIVATE);
        boolean value = sp.getBoolean("patrol",defValue);
        return value;
    }

    /**
     * 设置是否开启自由对话聊天
     * @param context
     * @param defValue
     */
    public static void setFreeChat(Context context,boolean defValue){
        SharedPreferences.Editor sp = context.getSharedPreferences(FREE_CHAT,Context.MODE_PRIVATE).edit();
        sp.putBoolean("isFreeChat",defValue);
        sp.commit();
    }

    /**
     *  获取是否开启自由聊天
     * @param context
     * @return
     */
    public static boolean getFreeChat(Context context){
        SharedPreferences sp = context.getSharedPreferences(FREE_CHAT,Context.MODE_PRIVATE);
        return sp.getBoolean("isFreeChat",true);
    }


    private final static String ROBOTMAPID="ROBOTMAPID";
    //地图id
    public static final String MAPID="mapId";
    /**
     * 存放机器人使用的地图id  存取值得键  MAPID
     */
    public static void putRobotMapId(Context context, int robotMapId) {
        SharedPreferences.Editor sp = context.getSharedPreferences(ROBOTMAPID, Context.MODE_PRIVATE).edit();
        sp.putInt(MAPID, robotMapId);
        sp.commit();
    }

    /**
     * 存放机器人使用的地图id    存取值得键   存取值得键  MAPID
     */
    public static int getRobotMapId(Context context) {
        SharedPreferences sp = context.getSharedPreferences(ROBOTMAPID, Context.MODE_PRIVATE);
        int value = sp.getInt(MAPID, -1);
        return value;
    }

}
